00001 // Emacs Mode Line: -*- Mode:c++;-*- 00002 // ------------------------------------------------------------- 00003 /* 00004 * Copyright (c) 2013 Battelle Memorial Institute 00005 * Licensed under modified BSD License. A copy of this license can be found 00006 * in the LICENSE file in the top level directory of this distribution. 00007 */ 00008 // ------------------------------------------------------------- 00009 /** 00010 * @file nonlinear_solver_interface.hpp 00011 * @author William A. Perkins 00012 * @date 2015-03-25 14:28:06 d3g096 00013 * 00014 * @brief 00015 * 00016 * 00017 */ 00018 // ------------------------------------------------------------- 00019 00020 #ifndef _nonlinear_solver_interface_hpp_ 00021 #define _nonlinear_solver_interface_hpp_ 00022 00023 #include <gridpack/math/vector.hpp> 00024 #include <gridpack/math/matrix.hpp> 00025 00026 namespace gridpack { 00027 namespace math { 00028 00029 // ------------------------------------------------------------- 00030 // class NonlinearSolverInterface 00031 // ------------------------------------------------------------- 00032 /// Interface to a solve system of nonlinear equations in parallel 00033 /** 00034 * This serves as a base for classes that solve a system of nonlinear 00035 * equations. While not strictly abstract, it has no function if 00036 * instantiated on its own. 00037 * 00038 * It encapuslates the nonlinear system solver of some 00039 * underlying implementation. The Pimpl idiom is used for \ref 00040 * NonlinearSolverImplementation "implementation", so user code is 00041 * completely independent of the underlying library. This class simply 00042 * provides an interface to a specific \ref 00043 * NonlinearSolverImplementation "implementation". Subclasses are 00044 * required to call p_set_impl() at construction to set the \ref 00045 * NonlinearSolverImplementation "implementation". 00046 */ 00047 template <typename T, typename I = int> 00048 class NonlinearSolverInterface 00049 { 00050 public: 00051 00052 typedef VectorT<T, I> VectorType; 00053 typedef MatrixT<T, I> MatrixType; 00054 00055 /// Default constructor. 00056 NonlinearSolverInterface() 00057 { 00058 } 00059 00060 /// Destructor 00061 virtual ~NonlinearSolverInterface(void) 00062 { 00063 } 00064 00065 /// Get the solution tolerance 00066 /** 00067 * 00068 * 00069 * 00070 * @return current solution tolerance 00071 */ 00072 double tolerance(void) const 00073 { 00074 return p_tolerance(); 00075 } 00076 00077 /// Set the solver tolerance 00078 /** 00079 * 00080 * 00081 * @param tol new solution tolerance 00082 */ 00083 void tolerance(const double& tol) 00084 { 00085 p_tolerance(tol); 00086 } 00087 00088 /// Get the maximum iterations 00089 /** 00090 * 00091 * 00092 * 00093 * @return current maximum number of solution iterations 00094 */ 00095 int maximumIterations(void) const 00096 { 00097 return p_maximumIterations(); 00098 } 00099 00100 00101 /// Set the maximum solution iterations 00102 /** 00103 * 00104 * 00105 * @param n new maximum number of iterations 00106 */ 00107 void maximumIterations(const int& n) 00108 { 00109 p_maximumIterations(n); 00110 } 00111 00112 /// Solve w/ the specified initial estimated, put result in same vector 00113 /** 00114 * This solves the system of nonlinear equations using the contents 00115 * of @c x as an initial solution estimate. The final result is 00116 * placed back in @c x upon completion. 00117 * 00118 * @param x solution Vector 00119 */ 00120 void solve(VectorType& x) 00121 { 00122 p_solve(x); 00123 } 00124 00125 protected: 00126 00127 /// Get the solution tolerance (specialized) 00128 virtual double p_tolerance(void) const = 0; 00129 00130 /// Set the solver tolerance (specialized) 00131 virtual void p_tolerance(const double& tol) = 0; 00132 00133 /// Get the maximum iterations (specialized) 00134 virtual int p_maximumIterations(void) const = 0; 00135 00136 /// Set the maximum solution iterations (specialized) 00137 virtual void p_maximumIterations(const int& n) = 0; 00138 00139 /// Solve w/ the specified initial estimated, put result in same vector 00140 virtual void p_solve(VectorType& x) = 0; 00141 00142 }; 00143 00144 00145 } // namespace math 00146 } // namespace gridpack 00147 00148 00149 #endif